package cz.muni.fi.pa165.restclient;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestTemplate;

/**
 * Main class of restclient command-line application dedicated to manipulation
 * of forests and pickers
 *
 * @author Matej Cimbora
 */
public class App {

    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        RestTemplate rt = new RestTemplate();
        PickerHandler pickerHandler = new PickerHandler(reader);
        ForestHandler forestHandler = new ForestHandler(reader);
        try {
            for (;;) {
                System.out.println("");
                System.out.println("1. " + "picker");
                System.out.println("2. " + "forest");
                System.out.println("Make your selection {1, 2}, x for exit");
                String result = reader.readLine();
                switch (result) {
                    case "1":
                        pickerHandler.pickerMenu();
                        break;
                    case "2":
                        forestHandler.forestMenu();
                        break;
                    case "x":
                        System.exit(0);
                    default:
                        System.out.println("Invalid choice, try again.");
                }
            }
        } catch (ResourceAccessException ex) {
            System.out.println("");
            System.out.println("Server is currently unavailable, application will close.");
            System.exit(1);
        } catch (Exception e) {
            System.out.println("Error has occured, application will close.");
            System.exit(2);
        }
    }
}